#include <Importer.hpp>
#include <scene.h>
#include <postprocess.h>

#include <stdio.h>

static const aiScene* pScene;
static Assimp::Importer gImporter;

//#define MODEL_PATH "./resource/male_base.dae"
#define MODEL_PATH "./resource/boblampclean.md5mesh"

#define LOAD_FLAG aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs

void printInfo(const aiMesh* paiMesh)
{
  bool bf=0, ff=0, nf=0, pf=0;
  if (paiMesh->HasBones())
    bf = true;
  if (paiMesh->HasFaces())
    ff = true;
  if (paiMesh->HasNormals())
    nf = true;
  if (paiMesh->HasPositions())
    pf = true;

  printf("Has Bones | Has Faces | Has Normals | Has Positions\n");
  printf("        %d           %d             %d               %d\n", bf, ff, nf, pf);

  int colorCH = paiMesh->GetNumColorChannels();
  int UVchannel = paiMesh->GetNumUVChannels();

  printf("Color Channel: %d\n", colorCH);
  printf("UV    Channel: %d\n", UVchannel);

  int mBone, mFace, mVtx, mUVcoord;
  mVtx = paiMesh->mNumVertices;
  mFace= paiMesh->mNumFaces;
  mBone= paiMesh->mNumBones;

  printf("Vertex count:  %d\n", mVtx);
  printf("Face   count:  %d\n", mFace);
  printf("Bone   count:  %d\n", paiMesh->mNumBones);

}

int main(int argc, char* argv[])
{
  // Load the mesh:
  pScene = gImporter.ReadFile(MODEL_PATH, LOAD_FLAG);

  if (!pScene)
    {
      printf("Error parsing file %s: %s\n", MODEL_PATH, gImporter.GetErrorString());
      return -1;
    }
  printf("Loaded file: %s\n", MODEL_PATH);

  // do something with global transform. Ignore it for now
  const size_t numMeshes = pScene->mNumMeshes;

  // How many meshes loaded??
  printf("Num of loaded meshes: %d\n", numMeshes);

  aiMesh* paiMesh;
  for(size_t i =0; i< numMeshes; i++)
    {
      paiMesh = pScene->mMeshes[i];

      printf("\nMesh #%d\n", i);
      printInfo(paiMesh);
    }
}
